package function;

import common.Location;
import common.PostJson;
import net.sf.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
<<<<<<< HEAD
 * Created by 陈 on 2018/1/24.
 */
public class InCityAction {
    private static String GET_ALL_LINES_URL = "http://106.15.43.138:8080/api/line/all_lines";
    //评价订单url
    private static String EVALUATE_URL = "http://106.15.43.138:8080/api/order/evaluate";
    //取消订单url
    private static String CANCLE_URL = "http://106.15.43.138:8080/api/order/passenger_cancel";


    //获取附近车辆url
    private static String NEARBYCAT_URL = "http://106.15.43.138:8080/api/user/nearbydriver2";

    //获取坐标所在市内线路url
=======
 * Created by 陈 on 2018/1/22.
 */
public class InCityAction {

    private static String GET_ALL_LINES_URL = "http://106.15.43.138:8080/api/line/all_lines";
    //评价订单
    private static String EVALUATE_URL = "http://106.15.43.138:8080/api/order/evaluate";
    //取消订单
    private static String CANCLE_URL = "http://106.15.43.138:8080/api/order/passenger_cancel";
    //创建订单
    private static String SUBMITORDER_URL = "http://106.15.43.138:8080/api/order/submit";

    //获取附近车辆
    private static String NEARBYCAT_URL = "http://106.15.43.138:8080/api/user/nearbydriver2";

    //获取坐标所在市内线路
>>>>>>> 1207614e70a64046cd073d03e79843dd6d7d03c1
    private static String GETINCITYLINE_URL = "http://106.15.43.138:8080/api/price/get_incity_line";

    //公式计价url
    private static String GETMETEREDFEE_URL = "http://106.15.43.138:8080/api/price/get_metered_fee";

<<<<<<< HEAD
    //调度费url
    private static String SCHEDULE_FEE_URL = "http://106.15.43.138:8080/api/order/add_schedule_fee";

=======
>>>>>>> 1207614e70a64046cd073d03e79843dd6d7d03c1
    //获取城内所有线路
    public static String getAllLinesInCity(){
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("version","0");
        String enJson = PostJson.encrypt(jsonObject.toString());
<<<<<<< HEAD
        String deJson = PostJson.post( enJson,GET_ALL_LINES_URL);
=======
        String deJson = PostJson.post(enJson,GET_ALL_LINES_URL);
>>>>>>> 1207614e70a64046cd073d03e79843dd6d7d03c1
        String aJson = PostJson.descrypt(deJson);
        return aJson;
    }


    //创建订单
<<<<<<< HEAD
    public static String createOrder(){
        return null;
    }

    //评价订单
    public static String commentOrder(JSONObject json){

        String aJson = PostJson.postJson(json, NEARBYCAT_URL);
        return aJson;

//        ArrayList arrayList = new ArrayList();
//        arrayList.add(1);
//        arrayList.add(2);
//        JSONObject jsonObject = new JSONObject();
//        jsonObject.put("uid",uid);
//        jsonObject.put("driver_id","asdsfas");
//        jsonObject.put("access_token",accessToken);
//        jsonObject.put("order_id","121232");
//        jsonObject.put("star","10");
//        jsonObject.put("problem",arrayList);
//        jsonObject.put("suggest","teswwwt");
//        String enJson = PostJson.encrypt(jsonObject.toString());
//        String deJson = PostJson.post(enJson,EVALUATE_URL);
//        String aJson = PostJson.descrypt(deJson);
//        System.out.println(aJson);
//
//        return aJson;
    }

    //取消订单
    public static String cancelOrder(JSONObject json){

        String aJson = PostJson.postJson(json, NEARBYCAT_URL);
        return aJson;

//        JSONObject jsonObject = new JSONObject();
//        jsonObject.put("uid",uid);
//        jsonObject.put("access_token",accessToken);
//        jsonObject.put("order_id","121230");
//        jsonObject.put("reason","test_reason");
//        jsonObject.put("reason_type","0");
//        String enJson = PostJson.encrypt(jsonObject.toString());
//        String deJson = PostJson.post(enJson,CANCLE_URL);
//        String aJson = PostJson.descrypt(deJson);
//        System.out.println(aJson);
//
//        return aJson;
    }

    //获取附近车辆
    public static String getNearByCar(JSONObject json){

        String aJson = PostJson.postJson(json, NEARBYCAT_URL);
        return aJson;

//        JSONObject jsonObject = new JSONObject();
//        Location location = new Location();
//        double lng = 118.086140;
//        double lat = 24.455018;
//
//        location.setLat(lat);
//        location.setLng(lng);
//        ArrayList arrayList = new ArrayList();
//        arrayList.add(location);
//        jsonObject.put("location",arrayList);
//        jsonObject.put("max_distance",1000);
//        String enJson = PostJson.encrypt(jsonObject.toString());
//        String deJson = PostJson.post(enJson,NEARBYCAT_URL);
//        String aJson = PostJson.descrypt(deJson);
//
//        return aJson;
    }

    //获取坐标所在市内线路,返回line_id
    public static String getInCityLine(JSONObject json){

        String aJson = PostJson.postJson(json, NEARBYCAT_URL);
        return aJson;

//        HashMap map = new HashMap();
//        JSONObject jsonObject = new JSONObject();
//        JSONObject start = new JSONObject();
//        JSONObject end = new JSONObject();
//        JSONObject startLocation = new JSONObject();
//        JSONObject endLocation = new JSONObject();
//        JSONObject elements = new JSONObject();
//
//
//        String startAddress = "xxx";
//        String startStreet = "xxx";
//        Double startLng = 118.086140;
//        Double startLat = 24.455018;
//
//        String endAddress = "xxx";
//        String endStreet = "xxx";
//        Double endLng = 118.086140;
//        Double endLat = 24.455018;
//
//        start.put("address",startAddress);
//        start.put("street",startStreet);
//        startLocation.put("lng",startLng);
//        startLocation.put("lat",startLat);
//        start.put("location",startLocation);
//
//        end.put("address",endAddress);
//        end.put("street",endStreet);
//        endLocation.put("lng",endLng);
//        endLocation.put("lat",endLat);
//        end.put("location",endLocation);
//
//        elements.put("start",start);
//        elements.put("end",end);
//
//        jsonObject.put("uid",uid);
//        jsonObject.put("access_token", accessToken);
//        jsonObject.put("elements",elements);
//        String enJson = PostJson.encrypt(jsonObject.toString());
//        String deJson = PostJson.post(enJson, GETINCITYLINE_URL);
//        String aJson  = PostJson.descrypt(deJson);
//
//        JSONObject resultJson = JSONObject.fromObject(aJson);
//
//        System.out.println(resultJson.get("status"));
//        map.put("message",resultJson.get("message"));
//        map.put("status",resultJson.get("status"));
//        map.put("line_id",resultJson.get("line_id"));
//        return map;
=======
    public static String createOrder(JSONObject json){
        String enJson = PostJson.encrypt(json.toString());
        String deJson = PostJson.post(enJson,SUBMITORDER_URL);
        String aJson = PostJson.descrypt(deJson);
        return aJson;
    }

    //评价订单
//    public static Map commentOrder(int uid,String driver_id, String order_id, int star,int problem,String suggest){
    public static String commentOrder(String uid,String accessToken){
        ArrayList arrayList = new ArrayList();
        arrayList.add(1);
        arrayList.add(2);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("uid",uid);
        jsonObject.put("driver_id","asdsfas");
        jsonObject.put("access_token",accessToken);
        jsonObject.put("order_id","121232");
        jsonObject.put("star","10");
        jsonObject.put("problem",arrayList);
        jsonObject.put("suggest","teswwwt");
        String enJson = PostJson.encrypt(jsonObject.toString());
        String deJson = PostJson.post(enJson,EVALUATE_URL);
        String aJson = PostJson.descrypt(deJson);
        System.out.println(aJson);

        return aJson;
    }

    //取消订单
    public static String cancelOrder(String uid,String accessToken){
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("uid",uid);
        jsonObject.put("access_token",accessToken);
        jsonObject.put("order_id","121230");
        jsonObject.put("reason","test_reason");
        jsonObject.put("reason_type","0");
        String enJson = PostJson.encrypt(jsonObject.toString());
        String deJson = PostJson.post(enJson,CANCLE_URL);
        String aJson = PostJson.descrypt(deJson);
        System.out.println(aJson);

        return aJson;
    }

    //获取附近车辆
    public static String getNearByCar(){
        JSONObject jsonObject = new JSONObject();
        Location location = new Location();
        double lng = 118.086140;
        double lat = 24.455018;

        location.setLat(lat);
        location.setLng(lng);
        ArrayList arrayList = new ArrayList();
        arrayList.add(location);
        jsonObject.put("location",arrayList);
        jsonObject.put("max_distance",1000);
        String enJson = PostJson.encrypt(jsonObject.toString());
        String deJson = PostJson.post(enJson,NEARBYCAT_URL);
        String aJson = PostJson.descrypt(deJson);

        return aJson;
    }

    //获取坐标所在市内线路,返回line_id
    public static Map getInCityLine(String uid, String accessToken){
        HashMap map = new HashMap();
        JSONObject jsonObject = new JSONObject();
        JSONObject start = new JSONObject();
        JSONObject end = new JSONObject();
        JSONObject startLocation = new JSONObject();
        JSONObject endLocation = new JSONObject();
        JSONObject elements = new JSONObject();


        String startAddress = "xxx";
        String startStreet = "xxx";
        Double startLng = 118.086140;
        Double startLat = 24.455018;

        String endAddress = "xxx";
        String endStreet = "xxx";
        Double endLng = 118.086140;
        Double endLat = 24.455018;

        start.put("address",startAddress);
        start.put("street",startStreet);
        startLocation.put("lng",startLng);
        startLocation.put("lat",startLat);
        start.put("location",startLocation);

        end.put("address",endAddress);
        end.put("street",endStreet);
        endLocation.put("lng",endLng);
        endLocation.put("lat",endLat);
        end.put("location",endLocation);

        elements.put("start",start);
        elements.put("end",end);

        jsonObject.put("uid",uid);
        jsonObject.put("access_token", accessToken);
        jsonObject.put("elements",elements);
        String enJson = PostJson.encrypt(jsonObject.toString());
        String deJson = PostJson.post(enJson, GETINCITYLINE_URL);
        String aJson  = PostJson.descrypt(deJson);

        JSONObject resultJson = JSONObject.fromObject(aJson);

        System.out.println(resultJson.get("status"));
        map.put("message",resultJson.get("message"));
        map.put("status",resultJson.get("status"));
        map.put("line_id",resultJson.get("line_id"));
        return map;
>>>>>>> 1207614e70a64046cd073d03e79843dd6d7d03c1

    }

    //公式计价
<<<<<<< HEAD
    public static String getMeteredFee(JSONObject json){

        String aJson = PostJson.postJson(json, NEARBYCAT_URL);
        return aJson;

//        int line_id = (int) getInCityLine(uid,accessToken).get("line_id");
//        JSONObject location = new JSONObject();
//        location.put("lng",118.123456);
//        location.put("lat",24.123456);
//
//        JSONObject json = new JSONObject();
//        json.put("uid", uid);
//        json.put("access_token", accessToken);
//        json.put("open_id", 1);
//        json.put("line_id", line_id);
//        json.put("car_level", 0);
//        json.put("car_type", 0);
//        json.put("car_seats", 5);
//        json.put("type", 1);
//        json.put("business_type",0);//包车
//        json.put("calc_type",1);
//        json.put("miles",500);
//        json.put("start_time",1234567);
//        json.put("location",location);
//        json.put("origin",0);
//        json.put("client_type",2);
//        json.put("version","1.0");
//        json.put("appoint_time","2016-10-09 16:14:46");
//        json.put("price_id","abcdefg");
//        json.put("car_class_id","asdfasdljlsdf");
//        json.put("minutes",50);
//        String enJson = PostJson.encrypt(json.toString());
//        String deJson = PostJson.post(enJson, GETMETEREDFEE_URL);
//        String aJson  = PostJson.descrypt(deJson);
//        System.out.println(aJson);
//        return aJson;
    }


    //优先叫车
    public static String CallCarFirst(JSONObject jsonObject){
        String aJson = PostJson.postJson(jsonObject, SCHEDULE_FEE_URL);
        return aJson;
}

    //获取司机虚拟电话
    public static String GetOwnPhone(JSONObject jsonObject){
        String aJson = PostJson.postJson(jsonObject, SCHEDULE_FEE_URL);
=======
    public static String getMeteredFee(String uid,String accessToken){

        int line_id = (int) getInCityLine(uid,accessToken).get("line_id");
        JSONObject location = new JSONObject();
        location.put("lng",118.123456);
        location.put("lat",24.123456);

        JSONObject json = new JSONObject();
        json.put("uid", uid);
        json.put("access_token", accessToken);
        json.put("open_id", 1);
        json.put("line_id", line_id);
        json.put("car_level", 0);
        json.put("car_type", 0);
        json.put("car_seats", 5);
        json.put("type", 1);
        json.put("business_type",0);//包车
        json.put("calc_type",1);
        json.put("miles",500);
        json.put("start_time",1234567);
        json.put("location",location);
        json.put("origin",0);
        json.put("client_type",2);
        json.put("version","1.0");
        json.put("appoint_time","2016-10-09 16:14:46");
        json.put("price_id","abcdefg");
        json.put("car_class_id","asdfasdljlsdf");
        json.put("minutes",50);
        String enJson = PostJson.encrypt(json.toString());
        String deJson = PostJson.post(enJson, GETMETEREDFEE_URL);
        String aJson  = PostJson.descrypt(deJson);
        System.out.println(aJson);
>>>>>>> 1207614e70a64046cd073d03e79843dd6d7d03c1
        return aJson;
    }
}
